﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using  System.Speech.Synthesis;

namespace TTS
{
    public class TTS
    {
        private static TTS _instance = new TTS();
        private List<string> message = new List<string>();
        private System.Speech.Synthesis.SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer();
        private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
        private TTS()
        {
            synth.Rate = 5;
            synth.SelectVoice("VW Liang");
            synth.Volume = 100;
            timer.Interval = 1000;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            if(message.Count >0)
            {

                string speakmessage = message[0];
                synth.SpeakAsyncCancelAll();
                synth.SpeakAsync(speakmessage);
                message.RemoveAt(0);
            }
        }

        
        public static TTS  instance()
        {
                if(_instance == null)
                {
                    _instance = new TTS();
                }
                return _instance;
        }

        public void AddVoice(string p)
        {
            message.Add(p);
        }

        public void Pause()
        {
            synth.Pause();
        }

        public void Resume()
        {
            synth.Resume();
        }

        public void Stop()
        {
            
        }
        
    }
}
